import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:hi_flutter/app_page.dart';

class AnimatedLogo extends AnimatedWidget {
  static final _opacityTween = Tween<double>(begin: 0.1, end: 1.0);
  static final _sizeTween = Tween<double>(begin: 0.0, end: 300.0);
  final Animation<double> animation;

  const AnimatedLogo({Key? key, required this.animation})
      : super(key: key, listenable: animation);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Opacity(
        opacity: _opacityTween.evaluate(animation),
        child: Container(
          margin: const EdgeInsets.symmetric(vertical: 10.0),
          height: _sizeTween.evaluate(animation),
          width: _sizeTween.evaluate(animation),
          child: const FlutterLogo(),
        ),
      ),
    );
  }
}

class AnimatePage5 extends StatefulWidget {
  const AnimatePage5({Key? key}) : super(key: key);

  @override
  AnimatePage5State createState() => AnimatePage5State();
}

class AnimatePage5State extends State<AnimatePage5> with SingleTickerProviderStateMixin {
  late AnimationController controller;
  late Animation<double> animation;

  @override
  initState() {
    super.initState();
    controller = AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);

    animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        controller.reverse();
      } else if (status == AnimationStatus.dismissed) {
        controller.forward();
      }
    });

    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return AppPage(
      body: AnimatedLogo(animation: animation),
    );
  }
  

  @override
  dispose() {
    controller.dispose();
    super.dispose();
  }
}
